import QtQuick 2.14
import QtQuick.Controls 2.14

Item {
    id: statusIndicator
    
    property string status: "idle"
    property string text: ""
    property int indicatorSize: 12
    
    implicitWidth: indicator.width + label.width + spacing
    implicitHeight: Math.max(indicator.height, label.height)
    
    property int spacing: 8
    
    Rectangle {
        id: indicator
        width: indicatorSize
        height: indicatorSize
        radius: indicatorSize / 2
        anchors.verticalCenter: parent.verticalCenter
        
        color: {
            switch (status.toLowerCase()) {
                case "idle":
                case "ready": return "#4CAF50"
                case "running":
                case "sampling": return "#2196F3"
                case "warning": return "#FF9800"
                case "error":
                case "failed": return "#F44336"
                case "maintenance": return "#9C27B0"
                case "offline":
                case "disconnected": return "#757575"
                default: return "#E0E0E0"
            }
        }
        
        // 闪烁动画用于运行状态
        SequentialAnimation {
            running: status.toLowerCase() === "running" || status.toLowerCase() === "sampling"
            loops: Animation.Infinite
            
            PropertyAnimation {
                target: indicator
                property: "opacity"
                from: 1.0
                to: 0.3
                duration: 800
            }
            PropertyAnimation {
                target: indicator
                property: "opacity"
                from: 0.3
                to: 1.0
                duration: 800
            }
        }
    }
    
    Text {
        id: label
        anchors.left: indicator.right
        anchors.leftMargin: spacing
        anchors.verticalCenter: parent.verticalCenter
        text: statusIndicator.text || getStatusText()
        color: "#212121"
        font.pixelSize: 14
        
        function getStatusText() {
            switch (status.toLowerCase()) {
                case "idle": return "空闲"
                case "ready": return "就绪"
                case "running": return "运行中"
                case "sampling": return "采样中"
                case "warning": return "警告"
                case "error": return "错误"
                case "failed": return "失败"
                case "maintenance": return "维护中"
                case "offline": return "离线"
                case "disconnected": return "未连接"
                default: return "未知状态"
            }
        }
    }
}